package com.woniuxy.project.util;

import com.woniuxy.commons.service.FeignRepaymentService;
import com.woniuxy.project.service.ProjectService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Component
public class ProjectExpireUtil {

    //  固定线程池，线程池中线程数量是固定的
    private static ExecutorService executors = Executors.newFixedThreadPool(10);

    @Resource
    private ProjectService projectService;

    @Resource
    private FeignRepaymentService repaymentService;

    public void handleStart(String pno){
        executors.execute(new StartRunnable(pno));
    }

    public void handleEnd(String pno){
        executors.execute(new EndRunnable(pno));
    }

    public void handleOverdue(String pno) {
        executors.execute(new OverdueRunnable(pno));
    }

    private class StartRunnable implements Runnable{

        private String pno;

        public StartRunnable(String pno){
            this.pno = pno;
        }

        @Override
        public void run() {
            projectService.startInviteTenders(pno);
        }

    }

    private class EndRunnable implements Runnable{

        private String pno;

        public EndRunnable(String pno){
            this.pno = pno;
        }

        @Override
        public void run() {
            projectService.endInviteTenders(pno);
        }

    }

    private class OverdueRunnable implements Runnable{

        private String pno;

        public OverdueRunnable(String pno){
            this.pno = pno;
        }

        @Override
        public void run() {
            repaymentService.checkRepaymentSuccess(pno);
        }

    }

}
